import { NestFactory,Reflector} from "@nestjs/core";
import { AppModule} from "./app.module";
import { HttpExceptionFilters } from "./CoreModule/filters/http-exception.filters";
import { ApiParamsValidationPipe } from "./CoreModule/pipes/api-params-validate.pipe";
import { ApiInterceptors } from "./CoreModule/interceptors.api.interceptors";
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';
import { RolesGuard } from "./CoreModule/guard/role.guard";
// import { MyLogger } from "./CoreModule/logger/log.service";

async function bootstrap(){
    const app = await NestFactory.create(AppModule);
    // const app = await NestFactory.create(AppModule,{logger:false});

    app.useGlobalFilters(new HttpExceptionFilters());
    app.useGlobalPipes(new ApiParamsValidationPipe(),new ValidationPipe({whitelist:true}));
    app.useGlobalGuards(new RolesGuard(new Reflector()));
    app.useGlobalInterceptors(new ApiInterceptors());
    // app.useLogger(app.get(MyLogger));

    const options = new DocumentBuilder()
    .setTitle('nest api')
    .setDescription('the api document of nest demo')
    .setVersion('0.0.1')
    .addTag('nest')
    .build();
    const document = SwaggerModule.createDocument(app,options);
    SwaggerModule.setup('api',app,document);

    await app.listen(8084);
}

bootstrap();